﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;

namespace Monitor
{
    class Monitor
    {
        public static Monitor Instance
        {
            get { return Nested.instance; }
        }

        class Nested
        {
            static Nested() { }
            internal static readonly Monitor instance = new Monitor();
        }

        static float cpuUsage, ramUsage, procUsage;

        public void getInfo()
        {
            // find out which OS is running
            switch (Environment.OSVersion.Platform)
            {
                case PlatformID.MacOSX:
                    Console.WriteLine("Install a decent OS");
                    break;
                case PlatformID.Unix:
                    break;
                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                    // get the information
                    PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); 
                    PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
                    // write the information
                    cpuUsage = cpuCounter.NextValue();
                    ramUsage = ramCounter.NextValue();
                    break;
            }
        }

        public void printInfo()
        {
            Console.WriteLine("CPU usage:       " + cpuUsage);
            Console.WriteLine("RAM usage:       " + ramUsage);
            Console.WriteLine("Processor usage: " + procUsage);
        }
    }
}
